const fs = require('fs');

fs.unlink('./e.json', (err) => {
  if(err) {
    throw err
  }else {
    console.log('delete!')
  }
})

// =============================

try {
  let res = fs.unlinkSync('./c.json');
  console.log(`同步删除文件：${res}`)
} catch (error) {
  throw error
}

// =====================
// 追加文件的另一种方式
let data = {
  name: 'Bill',
  job: 'CEO'
}
let res = fs.readFileSync('./a.json');
console.log(`原来的内容是：${res}`);
console.log('开始异步追加文件');

fs.appendFile('./a.json', JSON.stringify(data), (err) => {
  if(err) {
    throw err
  }else {
    let res = fs.readFileSync('./a.json');
    console.log(`文件异步追加成功！最新内容是：${res}`)
  }
})